﻿<cfscript>
/** 
* @hint "taskManager - Course Arrangement"
*/ 

component 
	extends="MachII.framework.Listener" 
	displayname="acadmicManager.listeners.senate.courseArrangeListener" 
	output=false 
	depends="senateMathAdvice, taskPropertyAdvice"
	{
	
	/**
	* @hint "Configures this listener as part of the Mach-II framework"
	*/
	public void function configure() output=false {} 
	
	/**
	* @hint "学期排课 删除单个教学任务排课计划"
	* 
	* @event "MachII Event Object"
	*/
	public void function taskClassDelete( required MachII.framework.Event event ) output=false {

		var sql = "";
		var queryObj = "";
		
		var taskId = event.getArg("TSK");
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 载入排课任务 */
			sql = "DELETE FROM t_task_arrange WHERE task_id = :taskId ";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
	
			/* 删除地点时间占用表 */
			sql = "DELETE FROM t_clsroom_timetable WHERE crtime_id IN (SELECT crtime_id FROM t_clsroom_forcourse WHERE task_id = :taskId ) ";

			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
						
			/* 删除教师时间占用表 */
			sql = "DELETE FROM t_teacher_timetable WHERE task_id = :taskId ";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
			/* 删除学生选课记录 */
			sql = "DELETE FROM t_student_course WHERE task_id = :taskId ";
			
			queryObj = new query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId", value=taskId, cfsqltype="cf_sql_varchar" );
			queryObj.execute( sql=sql );
			
		}
	}
	
	/**
	* @hint "学期排课 单个教学任务初始化"
	* 
	* @event "MachII Event Object"
	*/
	public void function taskClassInit( required MachII.framework.Event event ) output=false {
		
		var task = javaCast("null", "");
		var taskArrange = javaCast("null", "");

		var taskId = event.getArg("TSK");
		var taskType = event.getArg("TT");
		
		var taskWeek = [];
		var taskPeriod = [];

		var period = 0;
		var periodPerWeek = 0;
		var periodWeeks = 0;
		var wk = 0;
		
		var sql = "";
		
		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			 switch(taskType){
				case 'C':
					sql = "SELECT 
							  tsk_id, task_period, task_week, cidx, term_id, cid 
						   FROM 
							  t_common_task  
						   WHERE 
							  tsk_id = :taskId ";
					break;
				case 'P':
					sql = "SELECT 
							  tsk_id, task_period, task_week, cidx, term_id, cid 
						   FROM 
							  t_task tsk  
						   WHERE 
							  tsk.tsk_id = :taskId ";
					break;
				case 'R':
					sql = "SELECT 
							  tsk_id, task_period, task_week, cidx, term_id, cid 
						   FROM 
							  t_reopen_task tsk  
						   WHERE 
							  tsk.tsk_id = :taskId ";
					break;
				case 'T':
					sql = "SELECT 
							  tsk_id, task_period, task_week, cidx, term_id, cid 
						   FROM 
							  t_sport_task tsk  
						   WHERE 
							  tsk_id = :taskId ";
					break;
			}
			var queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="taskId",value=taskId, cfsqltype="cf_sql_varchar" );
			var rs_task = queryObj.execute(sql=sql).getResult();	  
			
			if (rs_task.recordCount GT 0) {

				/* 计算需排课总学时 */
				if (rs_task.task_period neq "0") {
					
					taskWeek = listToArray(rs_task.task_week, "-");
					taskPeriod = listToArray(rs_task.task_period, "+");
					
					periodWeeks = int(taskWeek[2]) - int(taskWeek[1]) + 1;
					
					for (wk in taskPeriod) {
						periodPerWeek = periodPerWeek + 1*wk;
					}
					
					period = periodWeeks * periodPerWeek;
					
				}
				
				/* 载入排课任务 */
				sql = "SELECT 1 FROM t_task_arrange WHERE task_id = :taskId ";
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId",value=taskId, cfsqltype="cf_sql_varchar" );
				rs_taskArrange = queryObj.execute(sql=sql).getResult();
		
				if (rs_taskArrange.recordCount EQ 0) {

					sql = "INSERT INTO t_task_arrange(
											task_id,term_id,cid,cidx,
											task_type,period_done,period_need
										)VALUES(
											:taskId, 
											:termId, 
											:courseId, 
											:courseIndex, 
											:taskType, 
											:periodDone, 
											:periodNeed 
										)";
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId",value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="termId",value=rs_task.term_id, cfsqltype="cf_sql_char" );
					queryObj.addParam( name="courseId",value=rs_task.cid, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="courseIndex",value=rs_task.cidx, cfsqltype="cf_sql_char" );
					queryObj.addParam( name="taskType",value=taskType, cfsqltype="cf_sql_char" );
					queryObj.addParam( name="periodDone",value=0, cfsqltype="cf_sql_integer" );
					queryObj.addParam( name="periodNeed",value=period, cfsqltype="cf_sql_integer" );
					queryObj.execute(sql=sql);
	
				}else{
					/* 设置需排总学时 */
					sql = "UPDATE t_task_arrange SET period_need = :periodNeed WHERE task_id = :taskId ";
					
					queryObj = new Query( datasource=application.dnsMaster );
					queryObj.addParam( name="taskId",value=taskId, cfsqltype="cf_sql_varchar" );
					queryObj.addParam( name="periodNeed",value=period, cfsqltype="cf_sql_integer" );
					
					queryObj.execute(sql=sql);
				}
			
			}
			
			
		}
		
		
	}
	
	/**
	* @hint "学期排课任务初始化"
	* 
	* @event "MachII Event Object"
	*/	
	public void function taskArrangeInit( required MachII.framework.Event event ) output=false {

		var propAdvice = gettaskPropertyAdvice();
		
		var termId = event.getArg("TID");
		
		var period = 0;
		var periodPerWeek = 0;
		var periodWeeks = 0;
		var wk = 0;
		
		var taskWeek = [];
		var taskPeriod = [];
		
		var rs_task = queryNew("tsk_id, cidx, term_id, cid, task_period, task_week, task_prop");
		var rs_lock = queryNew("tsk_id, task_prop");
		
		var sql = "";
		var queryObj = "";

		/* Every SQL operation is TRANSACATION*/
		transaction {
			
			/* 依次计算各项教学任务的排课学时数 */

			/* 处理计划课程 */
			sql = "SELECT 
					a.tsk_id, a.cidx, a.term_id, a.cid, a.task_period, a.task_week, a.task_prop 
					FROM t_task a 
					WHERE 
						a.term_id = :termId 
						AND 
						SUBSTR( a.task_prop, 7, 1 ) = '0'
						AND 
						NOT EXISTS ( 
							SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id
						) ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			for ( var a=1; a lte rs_task.recordCount; a++ ) {
				
				/* 计算需排课总学时 */
				period = 0;
				periodPerWeek = 0;
				periodWeeks = 0;
				
				if( rs_task['task_period'][a] neq "0" ){
					
					taskWeek = listToArray( rs_task['task_week'][a], "-" );
					taskPeriod = listToArray( rs_task['task_period'][a], "+" );
					
					periodWeeks = int( taskWeek[2] ) - int( taskWeek[1] ) + 1;
					
					for ( var wk in taskPeriod ) {
						periodPerWeek = periodPerWeek + 1 * wk;
					}
					
					period = periodWeeks * periodPerWeek;
				}
				
				/* 生成需排总学时 */
				sql = "INSERT INTO t_task_arrange 
							( 
								task_id, 
								term_id, 
								cid, 
								cidx, 
								task_type, 
								period_done, 
								period_need 
							) 
							VALUES 
							(
								:taskId,
								:termId,
								:courseId,
								:courseIndex,
								:taskType,
								:periodDone,
								:periodNeed 
							)";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=rs_task['term_id'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_task['cid'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="courseIndex", value=rs_task['cidx'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskType", value="P", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="periodDone", value=0, cfsqltype="cf_sql_integer" );
				queryObj.addParam( name="periodNeed", value=period, cfsqltype="cf_sql_integer" );
				queryObj.execute( sql=sql );
				
				/* 将已生成排课记录的教学任务设置为 禁止修改 模式 */
				propAdvice.parseProperty( rs_task['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
				
			}
			
			/* 处理全校通选课程 */
			sql = "SELECT 
					a.tsk_id, a.cidx, a.term_id, a.cid, a.task_period, a.task_week, a.task_prop 
					FROM t_common_task a 
					WHERE 
						a.term_id = :termId 
						AND 
						SUBSTR( a.task_prop, 7, 1 ) = '0'
						AND 
						NOT EXISTS ( 
							SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id
						) ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			for ( var a=1; a lte rs_task.recordCount; a++ ) {
				
				/* 计算需排课总学时 */
				period = 0;
				periodPerWeek = 0;
				periodWeeks = 0;
				
				if( rs_task['task_period'][a] neq "0" ){
					
					taskWeek = listToArray( rs_task['task_week'][a], "-" );
					taskPeriod = listToArray( rs_task['task_period'][a], "+" );
					
					periodWeeks = int( taskWeek[2] ) - int( taskWeek[1] ) + 1;
					
					for ( var wk in taskPeriod ) {
						periodPerWeek = periodPerWeek + 1 * wk;
					}
					
					period = periodWeeks * periodPerWeek;
				}
				
				/* 生成需排总学时 */
				sql = "INSERT INTO t_task_arrange 
							( 
								task_id, 
								term_id, 
								cid, 
								cidx, 
								task_type, 
								period_done, 
								period_need 
							) 
							VALUES 
							(
								:taskId,
								:termId,
								:courseId,
								:courseIndex,
								:taskType,
								:periodDone,
								:periodNeed 
							)";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=rs_task['term_id'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_task['cid'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="courseIndex", value=rs_task['cidx'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskType", value="C", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="periodDone", value=0, cfsqltype="cf_sql_integer" );
				queryObj.addParam( name="periodNeed", value=period, cfsqltype="cf_sql_integer" );
				queryObj.execute( sql=sql );
				
				/* 将已生成排课记录的教学任务设置为 禁止修改 模式 */
				propAdvice.parseProperty( rs_task['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
				
			}
			
			/* 处理单开班课程 */
			sql = "SELECT 
					a.tsk_id, a.cidx, a.term_id, a.cid, a.task_period, a.task_week, a.task_prop 
					FROM t_reopen_task a 
					WHERE 
						a.term_id = :termId 
						AND 
						SUBSTR( a.task_prop, 7, 1 ) = '0'
						AND 
						NOT EXISTS ( 
							SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id
						) ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			for ( var a=1; a lte rs_task.recordCount; a++ ) {
				
				/* 计算需排课总学时 */
				period = 0;
				periodPerWeek = 0;
				periodWeeks = 0;
				
				if( rs_task['task_period'][a] neq "0" ){
					
					taskWeek = listToArray( rs_task['task_week'][a], "-" );
					taskPeriod = listToArray( rs_task['task_period'][a], "+" );
					
					periodWeeks = int( taskWeek[2] ) - int( taskWeek[1] ) + 1;
					
					for ( var wk in taskPeriod ) {
						periodPerWeek = periodPerWeek + 1 * wk;
					}
					
					period = periodWeeks * periodPerWeek;
				}
				
				/* 生成需排总学时 */
				sql = "INSERT INTO t_task_arrange 
							( 
								task_id, 
								term_id, 
								cid, 
								cidx, 
								task_type, 
								period_done, 
								period_need 
							) 
							VALUES 
							(
								:taskId,
								:termId,
								:courseId,
								:courseIndex,
								:taskType,
								:periodDone,
								:periodNeed 
							)";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=rs_task['term_id'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_task['cid'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="courseIndex", value=rs_task['cidx'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskType", value="R", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="periodDone", value=0, cfsqltype="cf_sql_integer" );
				queryObj.addParam( name="periodNeed", value=period, cfsqltype="cf_sql_integer" );
				queryObj.execute( sql=sql );
				
				/* 将已生成排课记录的教学任务设置为 禁止修改 模式 */
				propAdvice.parseProperty( rs_task['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_reopen_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
				
			}

			
			/* 处理体育项目课程 */
			sql = "SELECT 
					a.tsk_id, a.cidx, a.term_id, a.cid, a.task_period, a.task_week, a.task_prop 
					FROM t_sport_task a 
					WHERE 
						a.term_id = :termId 
						AND 
						SUBSTR( a.task_prop, 7, 1 ) = '0'
						AND 
						NOT EXISTS ( 
							SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id
						) ";
			
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_task = queryObj.execute( sql=sql ).getResult();
			
			for ( var a=1; a lte rs_task.recordCount; a++ ) {
				
				/* 计算需排课总学时 */
				period = 0;
				periodPerWeek = 0;
				periodWeeks = 0;
				
				if( rs_task['task_period'][a] neq "0" ){
					
					taskWeek = listToArray( rs_task['task_week'][a], "-" );
					taskPeriod = listToArray( rs_task['task_period'][a], "+" );
					
					periodWeeks = int( taskWeek[2] ) - int( taskWeek[1] ) + 1;
					
					for ( var wk in taskPeriod ) {
						periodPerWeek = periodPerWeek + 1 * wk;
					}
					
					period = periodWeeks * periodPerWeek;
				}
				
				/* 生成需排总学时 */
				sql = "INSERT INTO t_task_arrange 
							( 
								task_id, 
								term_id, 
								cid, 
								cidx, 
								task_type, 
								period_done, 
								period_need 
							) 
							VALUES 
							(
								:taskId,
								:termId,
								:courseId,
								:courseIndex,
								:taskType,
								:periodDone,
								:periodNeed 
							)";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="termId", value=rs_task['term_id'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="courseId", value=rs_task['cid'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="courseIndex", value=rs_task['cidx'][a], cfsqltype="cf_sql_char" );
				queryObj.addParam( name="taskType", value="T", cfsqltype="cf_sql_char" );
				queryObj.addParam( name="periodDone", value=0, cfsqltype="cf_sql_integer" );
				queryObj.addParam( name="periodNeed", value=period, cfsqltype="cf_sql_integer" );
				queryObj.execute( sql=sql );
				
				/* 将已生成排课记录的教学任务设置为 禁止修改 模式 */
				propAdvice.parseProperty( rs_task['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_sport_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_task['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );

			}
			
			/* 将已生成排课记录的教学任务设置为 禁止修改 模式 */
			
			/* 处理计划课程 */	
			sql = "SELECT 
						a.tsk_id, a.task_prop 
						FROM t_task a 
						WHERE 
							a.term_id = :termId 
							AND 
							SUBSTR( a.task_prop, 1, 1 ) = '0' 
							AND 
							EXISTS( 
								SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)";
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_lock = queryObj.execute( sql=sql ).getResult();
			
			for ( var b=1; b lte rs_lock.recordCount; b++ ) {
				
				propAdvice.parseProperty( rs_lock['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_lock['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}
			
			/* 处理全校通选课程 */	
			sql = "SELECT 
						a.tsk_id, a.task_prop 
						FROM t_common_task a 
						WHERE 
							a.term_id = :termId 
							AND 
							SUBSTR( a.task_prop, 1, 1 ) = '0' 
							AND 
							EXISTS( 
								SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)";
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_lock = queryObj.execute( sql=sql ).getResult();
			
			for ( var b=1; b lte rs_lock.recordCount; b++ ) {
				
				propAdvice.parseProperty( rs_lock['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_common_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_lock['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}
			
			/* 处理单开班课程 */	
			sql = "SELECT 
						a.tsk_id, a.task_prop 
						FROM t_reopen_task a 
						WHERE 
							a.term_id = :termId 
							AND 
							SUBSTR( a.task_prop, 1, 1 ) = '0' 
							AND 
							EXISTS( 
								SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)";
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_lock = queryObj.execute( sql=sql ).getResult();
			
			for ( var b=1; b lte rs_lock.recordCount; b++ ) {
				
				propAdvice.parseProperty( rs_lock['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_reopen_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_lock['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}
			
			/* 处理体育项目课程 */	
			sql = "SELECT 
						a.tsk_id, a.task_prop 
						FROM t_sport_task a 
						WHERE 
							a.term_id = :termId 
							AND 
							SUBSTR( a.task_prop, 1, 1 ) = '0' 
							AND 
							EXISTS( 
								SELECT 1 FROM t_task_arrange b WHERE b.task_id = a.tsk_id AND b.term_id = :termId 
								)";
				
			queryObj = new Query( datasource=application.dnsMaster );
			queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
			
			rs_lock = queryObj.execute( sql=sql ).getResult();
			
			for ( var b=1; b lte rs_lock.recordCount; b++ ) {
				
				propAdvice.parseProperty( rs_lock['task_prop'][a] );
				propAdvice.setLocked( true );
				
				sql = "UPDATE t_sport_task SET task_prop = :taskProp WHERE tsk_id = :taskId";
				
				queryObj = new Query( datasource=application.dnsMaster );
				queryObj.addParam( name="taskId", value=rs_lock['tsk_id'][a], cfsqltype="cf_sql_varchar" );
				queryObj.addParam( name="taskProp", value=propAdvice.stringProperty(), cfsqltype="cf_sql_varchar" );
				queryObj.execute( sql=sql );
				
			}

		}
		
	}
	
}
	
</cfscript>